﻿using System;
using System.Diagnostics;
using System.Threading;

namespace GmailChecker.Utils
{
    static class App
    {
        public static volatile bool WaitDialogResult = false;        

        private static Mutex _mutex;

        public static bool IsUserInstanceExist()
        {
            int sid;

            using (Process p = Process.GetCurrentProcess())
            {
                sid = p.SessionId;
            }

            try
            {
                _mutex = Mutex.OpenExisting("GmailChecker" + sid);
            }
            catch
            {
                _mutex = new Mutex(true, "GmailChecker" + sid);

                return false;
            }

            return true;
        }

        public static void Exit(object sender, EventArgs e)
        {
            if (_mutex != null)
            {
                _mutex.Dispose();
            }
        }
    }
}
